// 在 search_job.js 中导入 recommend_list
import all_job_list from '../store/all_job_list';

// 定义参数类型
type Job = string;
type Salary = string;
type Education = string;
type City = string;

export function search_all_job_with_condition(job:Job, salary:Salary, education:Education, city:City) {
    // 创建请求体数据
    const requestData = {
        job: job,
        salary: salary,
        education: education,
        city: city
    };

    fetch('http://127.0.0.1:8000/search_all_job_with_condition', {
        method: 'POST',
        body: new URLSearchParams(requestData), // 将请求体数据转换为适合 FastAPI 的格式
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
    })
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            return response.json();
        })
        .then(data => {
            console.log(data);
            all_job_list.value = data.result;
        })
        .catch(error => {
            console.error('Error:', error);
        });
}


export function search_all_job_without_condition() {
    fetch('http://127.0.0.1:8000/search_all_job_without_condition', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
    })
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            return response.json();
        })
        .then(data => {
            console.log(data);
            all_job_list.value = data.result;
        })
        .catch(error => {
            console.error('Error:', error);
        });
}
